package com.bfg.model;

import java.util.Vector;
import java.util.HashMap;
import java.util.Iterator;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ResourceBundle;

public class Product {
	private static ResourceBundle sql_bundle = ResourceBundle
			.getBundle("com.bfg.model.SQLQueries");

	protected String pISBN;
	protected String pTitle;
	protected Vector pAuthors = new Vector();
	protected double pPrice;
	protected java.sql.Date pPubDate;
	protected String pDescription;
	protected static HashMap products = new HashMap();

	public String getISBN() {
		return pISBN;
	}

	public String getTitle() {
		return pTitle;
	}

	public Vector getAuthors() {
		return pAuthors;
	}

	private String getAuthorHREF(Author author) {
		return "<A HREF=\"/bfg/jsp/product/ByAuthor.jsp?author="
				+ author.getName() + "\">" + author.getName() + "</A>";
	}

	public String getAuthorString() {
		Vector authors = getAuthors();
		if (authors.size() == 1) {
			return (getAuthorHREF((Author) authors.elementAt(0)));
		}
		StringBuffer s = new StringBuffer();
		Iterator i = authors.iterator();

		while (i.hasNext()) {
			Author author = (Author) i.next();
			if (author == authors.firstElement()) {
				s.append(getAuthorHREF(author));
			} else {
				s.append("; " + getAuthorHREF(author));
			}
		}
		return (s.toString());
	}

	public double getPrice() {
		return pPrice;
	}

	public String getPriceString() {
		NumberFormat nf = NumberFormat.getCurrencyInstance();
		return nf.format(pPrice);
	}

	public java.sql.Date getPubDate() {
		return pPubDate;
	}

	public String getPubDateString() {
		SimpleDateFormat df = new SimpleDateFormat("MMM dd, yyyy");
		return (df.format(getPubDate()));
	}

	public String getDescription() {
		return pDescription;
	}

	public void setISBN(String ISBN) {
		pISBN = ISBN;
	}

	public void setTitle(String Title) {
		pTitle = Title;
	}

	public void setAuthors(Vector Authors) {
		pAuthors = Authors;
	}

	public void setPrice(double Price) {
		pPrice = Price;
	}

	public void setPubDate(java.sql.Date PubDate) {
		pPubDate = PubDate;
	}

	public void setDescription(String Description) {
		pDescription = Description;
	}

}
